<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>index</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../../../css/mui.min.css">
		<meta name="referrer" content="never" />
		<link rel="stylesheet" href="../work.css" />
		<link rel="stylesheet" href="../../static/css/common.css">
		<link rel="stylesheet" href="../../static/components/components.css" />
		<link rel="stylesheet" type="text/css" href="../../../../css/mui.picker.min.css" />
		 <link rel="stylesheet" type="text/css" href="../../../../css/mui.poppicker.css" />
		 <link rel="stylesheet" type="text/css" href="../../../../css/mui.picker.css" />
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.selsect-box{
				width: 40vw;
				height: 30px;
				border: 1px solid #999;
				line-height: 30px;
				box-sizing: border-box;
				padding-left: 5px;
			}
			.th{
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 10px;
				width: 85vw;
				height: 30px;
				align-items: center;
				background-color: #fafafa;
				box-sizing: border-box;
				padding: 0 5px;
				border: 1px solid #999;
			}
			.tr{
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 85vw;
				height: 40px;
				align-items: center;
				border:1px solid #999;
				border-top: none;
				box-sizing: border-box;
				padding: 0 5px;
			}
			.left-title{
				width: 30vw;
			}
			.right-ipt{
				width: 40vw;
				height: 30px;
				border: 0px 1px 1px 1px solid #fafafa
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav mui-bar-nav-bg">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">主变压器铁芯、夹地接地电流测试</h1>
		</header>
		<div class="mui-content" id="content">
			<div class="main_box">
				<div class="main_icon"></div>
				<div class="main_icon1"></div>
				<div class="box_title">
					<div class="icon"></div>
					<div style="font-size: 4vw;">基本信息</div>
				</div>
				<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />

				<div class="flex-between mt-10" >
					<div>本次测试记录</div>
<!-- 					<div @tap="addCheckItem" class="communication-add-btn">
						+
					</div> -->
				</div>
				<div style="margin-bottom: 20px;" v-for="(item,index) in list" :key="index">	
					<div class="th">
						<div class="">{{index + 1}}</div>
						<!-- <div class="color-red" @click="delItem(index)">删除</div> -->
					</div>
					<div class="tr">
						<div class="left-title">测量时间</div>
						<input :disabled="true" v-model="item.measureDate" maxlength="60" class="right-ipt"  />
					</div>
					<div class="tr">
						<div class="left-title">测量人</div>
						<input :value="'[' + item.measureStuffCode + ']' + item.measureStuffName" :disabled="true" maxlength="60" class="right-ipt" placeholder="请输入" />
					</div>
					<div class="tr">
						<div class="left-title">监护人</div>
						<input :value="'[' + item.tutelageStuffCode + ']' + item.tutelageStuffName" :disabled="true" maxlength="60" class="right-ipt" placeholder="请输入" />
					</div>
					<div class="tr">
						<div class="left-title">设备编号</div>
						<input :disabled="true" v-model="item.deviceCode" maxlength="60" class="right-ipt" placeholder="请输入" />
					</div>
					<div class="tr">
						<div class="left-title">设备名称</div>
						<input :disabled="true" v-model="item.deviceName" maxlength="60" class="right-ipt" placeholder="请输入" />
					</div>
					<div class="tr">
						<div class="left-title">测量温度℃</div>
						<input :disabled="true" v-model="item.temperature" maxlength="60" class="right-ipt" placeholder="请输入测量温度" />
					</div>
					<div class="tr">
						<div class="left-title">主变负荷MW</div>
						<input :disabled="true" v-model="item.mainCapacity" maxlength="60" class="right-ipt" placeholder="请输入主变负荷MW" />
					</div>
					<div class="tr">
						<div class="left-title">备注</div>
						<input :disabled="true" v-model="item.measureRemark" maxlength="60" class="right-ipt" placeholder="请输入备注" />
					</div>
				</div>	
				<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />


				<div class="flex-between list-head">
					<div class="flex-row" style="font-weight: bold;">
						<div class="icon"></div>
						流程日志
					</div>
				</div>
				<processlog :processlogid='workId'></processlog>
			</div>
			<div class="popup-bg" v-if="submitDia">
				<div style="padding: 15px 15px 0px" class="add-box">
					<div style="height: 5vh;" class="flex-row m-10">
						<div style="width: 70vw;font-size: 17px;">隐患描述
						</div>
					</div>
					<div style="max-height: 30vw;overflow: auto;">
						<div v-for="item in questiontArr">
							{{item.defectInfoDesc}}
						</div>
						<div style="text-align: center;" v-if="questiontArr.length==0">
							暂无数据
						</div>
					</div>
					<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />
					<div class=" m-10">
						<div style="width: 70vw;font-size: 17px;">其他情况说明</div>
						<textarea v-model="approveDes" maxlength="600"></textarea>
					</div>
					<div class="pop-bottom mt-10">
						<div @tap="submit('submit')">提交</div>
						<div class="color-red" @tap="submitDia = false">取消</div>
					</div>
				</div>
			</div>
			<div class="popup-bg" v-if="backOrApprove">
				<div style="padding: 5px 15px 0px" class="add-box">
					<div class="mt-10">
						<div>意见描述</div>
						<textarea :disabled="true" maxlength="255" placeholder="请输入审批意见" v-model="advance" class="mt-10"></textarea>
					</div>
					<hr size="1" style="color: #999;border-style: dashed; widows: 250px;" />
	
					<div class="pop-bottom">
						<div v-if="isBack" @tap="sendBack">退回</div>
						<div v-if="!isBack" @tap="notice">确认</div>
						<div class="color-red" @tap="backOrApprove = false">取消</div>
					</div>
				</div>
			</div>
			<div style="width: 100%;height: 60px;"></div>
			<div class="fixed-bottom flex-between">
<!-- 				<button class="submit_btn" v-if="workStatus <= 30 " @click="submit('save')">保存</button>
				<button class="submit_btn" v-if="workStatus == 20" @click="submitFormat">提交</button>
				<button class="cancel_btn" v-if="workStatus == 30 || workStatus == 40" @click="initApprove('back')">退回</button>
				<button class="submit_btn" v-if="workStatus == 30 || workStatus == 40" @click="initApprove('approve')">通过</button> -->
				
				
				<button @tap="goBack" class="cancel_btn">返回</button>
			</div>
		</div>
		</div>

		<!-- <div class="popup-bg" v-if="showSubmit" @click="showSubmit = false">
				<div class="add-box"  @click.stop="clickStop">
					<div class="flex-row user-form">
						<div class="pop-label">值班人</div>
						<input class="pop-ipt" />
					</div>
					<div class="pop-bottom">
						<div class="color-blue">提交</div>
						<div class="color-red" @click="showSubmit = false">取消</div>
					</div>
				</div> 
			</div> -->
		</div>


		<script src="../../../../js/mui.min.js"></script>
		<script src="../../../../js/vue.js"></script>
		<script type="text/javascript" src="../../../../js/jquery-3.2.1.min.js"></script>
		<script src="../../static/components/personSelect.js"></script>
		<script src="../../static/js/neiosCommon.js"></script>
		<script src="../../../../js/mui.picker.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../../js/mui.poppicker.js"></script>
		<script src="../../../../js/mui.picker.min.js"></script>
		<!--公共js页面必需-->
		<script type="text/javascript" src="../../static/js/neiosRequst.js"></script>
		<script src="../../static/components/processLog.js"></script>
		<!--流程日志-->
		<script type="text/javascript" charset="utf-8">
			document.addEventListener('focusout', function(e) {
				var classList = document.body.classList
				if (classList.contains('mui-focusin')) {
					classList.remove('mui-focusin')
				}
			})
			projectVM = new Vue({
				el: "#content",
				components: {
					personselect,
					processlog
				},
				data: {
					approveDes:'',
					defectInfoList:'',
					row:'',
					delList:[],
					isBack: false,
					backOrApprove: false,
					isSingle: true,
					weatherList:[],
					actionList:[],
					user: '',
					result: '',
					workStatus: '',
					workId: '',
					advance: '',
					status: '',
					mainCoreId:'',
					nowDate: '',
					checklist: [],
					status: '',
					questiontArr: [],
					delCheckItems: [],
					show_popup: false,
					list: [],
					checkItemNoteList: [],
					deviceSwitch: '',
					submitDia: false,
				},
				created() {
					let data = JSON.parse(localStorage.getItem("neiosGoDetail")) 
					console.log("HAHAHAH:"+JSON.stringify(data))
					this.workId = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.workId
					this.workStatus = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.workStatus
					this.workDesc = JSON.parse(localStorage.getItem('neiosGoDetail')).obj.workDesc
					this.user = JSON.parse(localStorage.getItem('neiosUser'))
					mui.init()
					
				},
				mounted: function() {
					this.getDictcode()
					this.getDetail()
					this.getNodeuser('user')
					this.getNowdate()
				},
				methods: {
					//确认
					notice(){		
									var param = {
										stationCode:this.user.stationCode,
										approveDes:this.advance,
										companyCode:this.user.companyCode,
										currentUser:this.user,
										workDesc:this.workDesc,
										workId:this.workId,
										workType:'0116'
									}
									console.log(JSON.stringify(param))
									// return
									mui.neiosRequst.httpRequst('/app/regularWork/mainTransCore/approveMainTransCoreInfo', param,
										(data)=> {
												mui.toast('操作成功')
												this.goBack()
										},
										function(data) {
									
										})
					},
					//删除
					delItem(index){
						var that = this
						var btnArray = ['取消', '确认'];
						mui.confirm('是否确认删除?', '', btnArray, function(e) {
							if (e.index == 1) {
								if(that.list[index].mainCoreInfoId != ''){
									that.delList.push(that.list[index])
								}
								that.list.splice(index,1)
								
							} else {
								
							}
						})
						
					},
					//选择动作原因
					showAction(index){
						var that = this
					 let picker = new mui.PopPicker({
						 layer:1
					 })	
					 var list = []
					 this.actionList.forEach((item,index)=>{
						 list.push({'text':item.itemText,value:index})
					 })
					 picker.setData(list)
					  picker.show(function(e) {   //e 就是总数据的数组 显示picker
						that.list[index].actCause = e[0].value + 1
					})
					},
					//选择天气
					showWeather(index){
						var that = this
					 let picker = new mui.PopPicker({
						 layer:1
					 })	
					 var list = []
					 this.weatherList.forEach((item,index)=>{
					 						 list.push({'text':item.itemText,value:index})
					 })
					 picker.setData(list)
					  picker.show(function(e) {   //e 就是总数据的数组 显示picker
						that.list[index].weather = e[0].value + 1
					})
					},
					//判断是否显示办理
					isShowHandle() {
						if (this.workStatus == '30') {
							return true
						} else {
							return false
						}
					},
					//判断是否显示编辑
					isShowEdit() {
						if (this.workStatus == '20') {
							return true
						} else {
							return false
						}
					},
					//提交校验
					submitFormat(){
						var arr = this.list
						var able = true
					arr.forEach(item => {
						if(item.deviceCode == ''){
							mui.toast('请输入设备编号')
							able = false
							return
						}
						else if(item.deviceName == ''){
								mui.toast('请输入设备名称')
								able = false
								return
						}
						else if(item.temperature == ''){
								mui.toast('请输入测量温度')
								able = false
								return
						}
						else if(item.mainCapacity == ''){
								mui.toast('请输入主变负荷')
								able = false
								return
						}
						else if(item.measureRemark == ''){
								mui.toast('请输入备注')
								able = false
								return
						}
					});	
					if(able){
						this.submit('submit')
					}
					},
					//添加	
					addCheckItem() {
						var _this = this
					let info = {
						arresterInfoId:'', // 明细主键
						arresterActionId:'', // 批次主键
						areaCompanyCode:_this.user.companyCode, // 区域编号
						areaCompanyName:_this.user.companyName, // 区域名称
						stationCode:_this.user.stationCode, // 场站编号
						stationName:_this.user.stationName, // 场站名称
						newAreaCode:_this.user.companyNewCode, // 新能源分公司编号
						newStationCode:_this.user.stationNewCode, // 新能源场站编号
						actionTime: _this.nowDate,
						measureStuffCode: _this.user.userId, // 记录人编号
						measureStuffName: _this.user.name,// 新增时测试人为当前登陆人
						tutelageStuffCode: _this.tutelageStaffCode, // 监护人
						tutelageStuffName:_this.tutelageStaffName,
						weather:'', //天气情况
						deviceName:'',//设备名称
						counter:'',
						actCount:'',
						leakageCurrent:'',
						leakageStandard:'',
						actCause:'',
						remark:'',
						dataStatus:'1',// 是否有效
						createBy : _this.user.userId,// 创建人员
						createStaffName : _this.user.name,// 创建人姓名
						createDate : _this.nowDate,// 创建时间
						modifyBy : _this.user.userId,// 修改人员
						modifyStaffName : _this.user.name,// 修改人员姓名
						modifyDate :  _this.nowDate,// 修改时间
						measureDate:_this.nowDate
					}
					this.list.unshift(info)
					mui.toast('添加成功')
					},
					//返回上一页
					goBack() {
						setTimeout(function() {
							let page2 = plus.webview.getWebviewById("../sitOperation/terminalwork/terminalwork.html");
							let param = {}
							param.isRefresh = true
							mui.fire(page2, 'isRefresh', param);
							mui.back()
						}, 1000);
						
					},
					//保存提交
					submit(e, f) {
					
						var that = this
						var url = '/app/regularWork/mainTransCore/saveOrUpdateMainTransCoreInfo'
						if(e == 'save'){
							this.list.forEach(item=>{
								item.tutelageStuffCode = this.tutelageStaffCode
								item.tutelageStuffName = this.tutelageStaffName
							})
						}
						var param = {
							mainTransCore:{
								mainCoreId:this.mainCoreId,
								areaCompanyCode:this.user.companyCode,
								newAreaCode:this.user.companyNewCode,
								stationCode:this.user.stationCode,
								newStationCode:this.user.stationNewCode,
								workDesc:this.workDesc,
								workId:this.workId
							},
							mainTransCoreInfoList:this.list,	
							currentUser:this.user,
							delMainTransCoreInfoList:this.delList
						}	
						if(e == 'submit'){
							param.workId = this.workId
							param.workType = '0116'
							param.workDesc = this.workDesc
							param.tutelageStuffCode = this.tutelageStaffCode
							param.tutelageStuffName = this.tutelageStaffName
							
							url = '/app/regularWork/mainTransCore/submitMainTransCoreInfo'
						}
						console.log(JSON.stringify(param))
						 // return
						mui.neiosRequst.httpRequst(url, param,
							(data)=> {
								console.log(JSON.stringify(data))
								if(data.code != 0){
									mui.toast(data.msg)
									return
								}
								mui.toast('操作成功')
								if (e != 'save') {
									this.goBack()
								} else {
									setTimeout(function() {
									mui.back()
									}, 1000);
								}
							},
							function(data) {

							})
					},
				
					getName(data) {
						console.log(data)
						if (data) {
							let list = []
							data.split(',').map((v) => {
								list.push(v.split(']')[1])
							})
							return list.join(',');
						} else {
							return data
						}

					},
					//切换结论
					changeswitchRemark() {
						var arr = this.checkItemNoteList
						this.questiontArr = []
						var questiontRxt = []
						var that = this
						arr.forEach(item => {
							if (item.checkItemResult > 1) {
								var txt = item.checkItemResult == 2 ? '不合格' : '告警'
								questiontRxt.push(item.checkItemContent + '。' + txt + '。')
								that.questiontArr.push({
									name: item.checkItemContent + '。' + txt,
									reson: ''
								})
							}
						});
						console.log(JSON.stringify(that.questiontArr))
						this.$nextTick(() => {
							that.deviceSwitch.switchRemark = '切换试验结论：' + questiontRxt.join('')
							if (that.questiontArr.length == 0) {
								that.deviceSwitch.switchRemark = ''
							}
						})
					},
					initApprove(type) {
						if (type == 'back') {
							this.isBack = true
						} else {
							this.isBack = false
						}
						this.backOrApprove = true
						var arr = this.list
						this.questiontArr = []
						var that = this
						arr.forEach(item => {
							if (item.leakageCurrent > item.leakageStandard) {
								this.questiontArr.push({
									defectInfoDesc: item.deviceName +'避雷器泄露电流越限'
								})
							}
						});
					},
					//获取当前时间
					getNowdate() {
						var date = new Date()
						var year = date.getFullYear()
						var month = date.getMonth()
						var day = date.getDate()
						var hour = date.getHours()
						var min = date.getMinutes()
						 var sec = date.getSeconds()
						month = month*1 + 1
						if (month.toString().length < 2) {
							month = '0' + month
						}
						if (day.toString().length < 2) {
							day = '0' + day
						}
						if (hour.toString().length < 2) {
							hour = '0' + hour
						}
						if (min.toString().length < 2) {
							min = '0' + min
						}
						if (sec.toString().length < 2) {
							sec = '0' + sec
						}
						this.nowDate = year + '-' + month + '-' + day + ' ' + hour + ':' + min +':' + sec	
					},
					//流程退回
					sendBack() {
						if (this.advance == '') {
							mui.toast('请输入意见描述')
							return
						}
						var that = this
						var param = {
							"workId": this.workId,
							"workType": "0116",
							"nodeDealStaffCode": this.user.userId,
							"nodeDealStaffName": this.user.name,
							"approveDes": this.advance,
							"nodeDealStaffRole": '1',
							"forwardNode": '1',
							"nodeVisibleRange": '20',
							"workDesc":this.workDesc
						}
						mui.neiosRequst.httpRequst('/app/personWork/sendBack', param,
							(data)=> {
								mui.toast('操作成功')
								this.goBack()
							},
							function(data) {

							})
					},
					//获取默认参数
					getStationCode(){
						var _this = this
						var param = {
							newStationCode:this.user.stationNewCode
						}
						mui.neiosRequst.httpRequst('/app/regularWork/mainTransCore/getLastMainTransCoreInfoList', param,
							(data)=> {
								var list = data.data
								list.forEach(e=>{
									let Info = {
									mainCoreInfoId: '', // 明细主键
									mainCoreId: '', // 批次主键
									measureDate: _this.nowDate,
									measureStuffName: _this.user.name,// 新增时测试人为当前登陆人
									measureStuffCode: _this.user.userId,
									tutelageStuffCode: _this.tutelageStaffCode,//监护人
									tutelageStuffName: _this.tutelageStaffName,
									deviceCode: e.deviceCode,// 设备编号
									deviceName: e.deviceName,//设备名称
									measureValue: '',
									temperature: '',
									mainCapacity: '',
									measureRemark: '',
								}
								_this.list.push(Info)
							
								})
							},
							function(data) {
						
							})
					},
					//获取监护人
					getNodeuser(e){
						var that = this
						var param = {
						workId:this.workId
						}
						mui.neiosRequst.httpRequst('/app/personWork/getNodeLogByWorkId', param,
							(data)=> {
								var nodeLogList = data.data;
								 // 新增时监护人信息
								let tutelageStaffInfo = nodeLogList.filter(v=>v.node_deal_staff_code.toUpperCase() != this.user.userId);
								if(tutelageStaffInfo.length > 0){
								let tutelageStaff = tutelageStaffInfo[0];
								that.tutelageStaffName= tutelageStaff.node_deal_staff_name;
								that.tutelageStaffCode= tutelageStaff.node_deal_staff_code;
								}
								if(e != 'user'){
									that.getStationCode()
								}
							},
							function(data) {
						
							})
					},
					//获取工作详情
					getDetail() {
						var that = this
						var param = {
							workId:this.workId
						}
						mui.neiosRequst.httpRequst('/app/regularWork/mainTransCore/getMainTransCoreInfoList', param,
							(data)=> {
								
								that.mainCoreId = data.data.mainCoreId == null ? '' :  data.data.mainCoreId
								console.log(that.mainCoreId)
								that.list = data.data.mainTransCoreInfoList == null ? [] : data.data.mainTransCoreInfoList
								if(that.mainCoreId == '' && that.list.length < 1){
									that.getNodeuser()
								}
	
							},
							function(data) {
						
							})
					},
					//获取检查参数
					getDictcode() {
						var that = this
						var param = {
							dictCode: "ARRESTER_ACTCAUSE,ARRESTER_WEATHER"
						}
						mui.neiosRequst.httpRequst('/app/common/getItemsByDictCodes', param,
							function(data) {
							 that.actionList = data.data.ARRESTER_ACTCAUSE
							 that.weatherList = data.data.ARRESTER_WEATHER

							},
							function(data) {

							})
					},


				},

			})
		</script>
	</body>

</html>
